class Solution {
public:
    vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {
        
        vector<vector<int>> vecRet;
        int left=newInterval[0],right=newInterval[1];
        bool bFlg=false;
        for(int i=0;i<intervals.size();++i){
            if(intervals[i][0]>right){
                if(!bFlg){
                    vecRet.push_back({left,right});
                    bFlg=true;
                }
                vecRet.push_back(intervals[i]);
            }
            else if(intervals[i][1]<left){
                vecRet.push_back(intervals[i]);
            }
            else{
                left=min(intervals[i][0],left);
                right=max(right,intervals[i][1]);
            }
        }
        if(!bFlg){
            vecRet.push_back({left,right});
        }

        return vecRet;
    }
};
